#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
#if UNITY_EDITOR
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Serialization;
using UnityEditor;
using UnityEngine;
using System.Reflection;
using System.Collections.Generic;
using System.Runtime.InteropServices;

[Serializable]
public class AudioSetting
{
    public enum Plugins
    {
        Debug,
        Profile,
        Release,
    }

    public Plugins CurrentPlugin;

	public string WwiseProjectPath;
	public string SoundbankPath;
    public bool CreateWwiseGlobal = true;
    public bool CreateWwiseListener = true;
	public bool ShowMissingRigidBodyWarning = true;
    public string WwiseInstallationPathWindows;
    public string WwiseInstallationPathMac;
    public bool CreatedPicker = false;
    public string EditorSoundbankPath;
    public bool LoadBankFromExportPath = false;
    public bool CopySoundBanksAsPreBuildStep = true;
    public bool GenerateSoundBanksAsPreBuildStep = false;
    public bool AudioApplyButtonMode = false;

    public const string WwiseSettingsFilename = "..//AudioSetting.xml";
	
	static AudioSetting s_Instance = null;    


    public AudioSetting()
    {
    }


    static public AudioSetting Instance
    {
        get
        {
            if(s_Instance != null)
            {
                return s_Instance;
            }
            else
            {
                s_Instance = LoadSettings();
                return s_Instance;
            }
        }
    }


	public string FullWwiseProjectPath
	{
		get
		{
			return AkUtilities.GetFullPath(Application.dataPath, WwiseProjectPath);
		}
	}

	public string WwiseProjectDirectory
	{
		get
		{
			return Path.GetDirectoryName(FullWwiseProjectPath);
		}
	}

	public string WwiseProjectFileNameWithoutExtension
	{
		get
		{
			return Path.GetFileNameWithoutExtension(WwiseProjectPath);
		}
	}
	public string FullWwiseGeneratedSoundBanksPath
	{
		get
		{
			return Path.Combine(WwiseProjectDirectory, SoundbankPath);
		}
	}

	// Save the AudioSetting structure to a serialized XML file
	public static void SaveSettings(AudioSetting Settings)
	{
		try
		{
			XmlDocument xmlDoc = new XmlDocument();
			XmlSerializer xmlSerializer = new XmlSerializer(Settings.GetType());
			using (MemoryStream xmlStream = new MemoryStream())
			{
				StreamWriter streamWriter = new StreamWriter( xmlStream, System.Text.Encoding.UTF8 );
				xmlSerializer.Serialize(streamWriter, Settings);
				xmlStream.Position = 0;
				xmlDoc.Load(xmlStream);
				xmlDoc.Save(Path.Combine(Application.dataPath, WwiseSettingsFilename));
			}
		}
		catch (Exception)
		{
			return;
		}
	}
	
	// Load the AudioSetting structure from a serialized XML file
	public static AudioSetting LoadSettings(bool ForceLoad = false)
	{
		if (s_Instance != null && !ForceLoad)
            return s_Instance;
			
		AudioSetting Settings = new AudioSetting();
		try
		{
			if (File.Exists(Path.Combine(Application.dataPath, WwiseSettingsFilename)))
			{
				XmlSerializer xmlSerializer = new XmlSerializer(Settings.GetType());
				FileStream xmlFileStream = new FileStream(Application.dataPath + "/" + WwiseSettingsFilename, FileMode.Open, FileAccess.Read);
				Settings = (AudioSetting)xmlSerializer.Deserialize(xmlFileStream);
				xmlFileStream.Close();
			}
			
			s_Instance = Settings;
		}
		catch (Exception)
		{
		}
		
		return Settings;
	}
}


// public partial class AkBasePathGetter
// {
// 	static partial void GetWwiseGeneratedSoundBanksPath(ref string bankpath)
// 	{
// 		//bankpath = AudioSetting.Instance.FullWwiseGeneratedSoundBanksPath;
// 	}
// }

#endif //UNITY_EDITOR
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.